<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>开门惊喜资源管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <!--[if lt IE 9]>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/html5.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/respond.min.js"></script>
    <![endif]-->
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js" type="text/javascript"></script>
    <%-- <script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>--%>
	<style type="text/css">
	.submit{ 
	  			height: 40px; 
	     		width: 290px; 
	     		font-size: 24px !important; 
	     		font-family: 微软雅黑; 
	     		color:white !important; 
	     		background-color: #62d2fc !important; 
	     		border-color: #62d2fc !important; 
	 			border: 1px solid transparent; 
	 			border-radius: 4px; 
	  		}
	  		
        .box1{
        	text-align: center;
            font-size: 18px;
            width: 100px;
            color: black;
            padding: 10px;
            margin: 10px;
            -webkit-border-radius: 15px;
            -moz-border-radius: 15px;
            background-color: #FBFBFB;
			border: 1px solid balck;
        }
        .box2{
        	text-align: center;
            font-size: 18px;
            width: 100px;
            padding: 10px;
            -webkit-border-radius: 15px;
            -moz-border-radius: 15px;
            background: #D2D2D2;
    		color: black;
   			 border: 1px solid #D2D2D2;
        }
        .box3{
        	text-align: center;
            font-size: 15px;
            width: 100px;
            padding: 10px;
            -webkit-border-radius: 15px;
            -moz-border-radius: 15px;
            background: white;
    		color: black;
    		border: 1px solid #AFAAAA;
        }
        .box4{
        	text-align: center;
		    font-size: 15px !important;
		    width: 61px;
		    height: 28px;
		    -webkit-border-radius: 15px;
		    -moz-border-radius: 15px !important;
		    background: white;
		    color: black !important;
		    border: 1px solid #AFAAAA;
        }
		.box1:hover{color: black;}
		.box2:hover{color: black;}
		.li1{
			padding: 0 4px !important;
		}
		.list1{
			padding: 8px 0 0;
		}
		.resource{
			margin: 20px 18px 18px 20px;
		}
		.resource_img{
			width: 285px;
			height: 285px;
		}
		.inputDisable{
			cursor: not-allowed !important;
		}
		.left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.list-tab li{
			*+padding:0px 10px 10px;
		}
		.list-header{
			
		}
		.btn{
			*width:60px;
		}
		.lt{
			float:left;
		}
		.ui-pg-button{
			*background:#ccc;
		}
		.col-md-3{
			*width:100px;
		}
		.form-group{
			*overflow: hidden;
		}
		.pagination{
			*margin-left:50%;
		}
	</style>
</head>
<body view="menu-item-4852">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
    <div style="border: 1px solid #e7e7e7;padding: 0;min-height: 300px;*margin-left:270px;">
        <div class="list-header">
            <div class="list-header-title">
                <h5>资源库管理</h5>
                <div class="resource_tools">
                    <ul id="action">
                    </ul>
                </div>
            </div>
            <div class="list-tab">
                <ul>
                    <li>
                    	<a href="/admin/tshelves_listView.action?flag=2" class="box2" id="a1">公共资源</a>
                    </li>
                    <li>
                    	<a href="/admin/tshelves_listView.action?flag=3" class="box1" id="a2">私有资源</a>
                    </li>
                </ul>
            </div>
        <div class="panel-body">
            <div class="resource-list">
                <c:forEach items="${page.recordList}" var="map" varStatus="status">
                    <div class="resource">
                        <img class="resource_img" src="${IMG_SERVER}${map.content}">
                        <h5 class="resource_title">${map.name}
                        <span class="sold">
                            <c:if test="${map.isonline == 0}">未分配</c:if>
                            <c:if test="${map.isonline == 1}">已下架</c:if>
                            <c:if test="${map.isonline == 2}">已分配</c:if>
                        </span>
                        </h5>
                        <div class="tags">
                            <div class="tag"><c:if test="${map.type == 'I'}">图片</c:if>
                                <c:if test="${map.type == 'M'}">多媒体</c:if></div>
                            <c:if test="${!empty map.visiable}">
                                <div class="tag">
                                    <c:if test="${map.visiable == 1}">自动隐藏</c:if>
                                    <c:if test="${map.visiable == 0}">不隐藏</c:if>
                                </div>
                            </c:if>
                            <span class="ctime"><fmt:formatDate value="${map.ctime}" pattern="yyyy-MM-dd"/></span>
                        </div>
                        <h5>
                            <em>显示日期：</em>
                            <c:if test="${!empty map.timeFrom}">
                                ${map.timeFrom} 至 ${map.timeTo}
                            </c:if>
                        </h5>
                        <h5>
                            <em>显示时间：</em>
                            <c:if test="${!empty map.showTime}">
                                ${map.showTime} 至  ${map.expiredTime}
                            </c:if>
                        </h5>
                        <h5>
                            <em>跳转URL：</em>
                                ${map.curl}
                        </h5>
<!--                         <h5> -->
<!--                             <em>点击次数：</em> -->
<!--                                 0 -->
<!--                         </h5> -->
                        <h5>
                            <em>资源所属：</em>
                                <c:if test="${map.dtype == 1}">平台资源</c:if>
                                <c:if test="${map.dtype == 2}">${map.agtName}</c:if>
                        </h5>
                        <div class="list-tab list1">
	                        <ul >
	                         <c:forEach items="${buttonMap}" var="button" varStatus="status">
	                         	<c:if test="${button.mName == '开门惊喜报表'}">
	                         		<li class="li1"><input name="report" id="report" class="box4" type="button" value="报表" onclick="reports(${map.sid })"></li>
	                         	</c:if>
	                         	<c:if test="${(map.isonline == 0 || map.isonline == 2) && button.mName == '开门惊喜分配'}">
	                         		<li class="li1">
				                		<input name="distribute" id="distribute" class="box4" type="button" value="分配" onclick="distribute(${map.sid })">
				                	</li>
	                         	</c:if>
	                         	<c:if test="${map.isonline == 0 || map.isonline == 2}">
		                         	<c:if test="${(userRole==1||userRole==2) && button.mName == '开门惊喜编辑'}">
			                         	<li class="li1"><input name="edit" id="edit" class="box4" type="button" value="编辑" onclick="editRow(${map.sid })"></li>
		                         	</c:if>
		                         	<c:if test="${(userRole==3||userRole==4) && map.agtcode == agt && button.mName == '开门惊喜编辑'}">
			                         	<li class="li1"><input name="edit" id="edit" class="box4" type="button" value="编辑" onclick="editRow(${map.sid })"></li>
		                         	</c:if>
	                         	</c:if>
	                         	<c:if test="${button.mName == '开门惊喜下架'}">
	                         		<li class="li1">
				                		<c:if test="${map.isonline == 0}">
				                		<input name="offShelves" id="offShelves" class="box4 inputDisable" type="button" value="下架" disabled="disabled">
				                		</c:if>
					                	<c:if test="${map.isonline == 2}">
					                	<input name="offShelves" id="offShelves" class="box4" type="button" value="下架" onclick="off(${map.sid })">
					                	</c:if>
				                	</li>
	                         	</c:if>
	                          </c:forEach>
	                         </ul>
            			</div>
                    </div>
                </c:forEach>
            </div>
            <c:if test="${page.recordList.size() > 0}">
                <div class="page_field" style="text-align: center;">
                    <nav>
                        <ul class="pagination pagination-lg">
                            <!--上一页-->
                            <c:if test="${page.currentPage == 1}">
                                <li class="disabled">
                                    <a href="#" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                            </c:if>
                            <c:if test="${page.currentPage != 1}">
                                <li>
                                    <a onclick="page(${page.currentPage-1})" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                            </c:if>


                            <c:forEach begin="${page.beginPageIndex}" end="${page.endPageIndex}" step="1" var="v">
                                <c:if test="${page.currentPage == v}">
                                    <li class="active"><a href="#">${v}</a></li>
                                </c:if>
                                <c:if test="${page.currentPage != v}">
                                    <li><a onclick="page(${v})">${v}</a></li>
                                </c:if>
                            </c:forEach>

                            <!-- 下一页--->
                            <c:if test="${page.currentPage == page.pageCount}">
                                <li class="disabled">
                                    <a href="#" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </c:if>
                            <c:if test="${page.currentPage != page.pageCount}">
                                <li>
                                    <a onclick="page(${page.currentPage+1})" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </c:if>
                        </ul>
                    </nav>
                </div>
            </c:if>
        </div>
    </div>
</div>
</div>
<script type="text/javascript">
    $(document).ready(
            function () {
                		var data = ${buttonJson};
//                         data = eval("(" + buttonJson + ")");
                        for (var i in data) {
                            var action = data[i].mName;
                            switch (action) {
                                case "开门惊喜上架":
                                    $("#action").append('<li><a class="resource_oper default" onclick="addRow();"><i class="glyphicon glyphicon-plus"></i>上架资源</a></li>');
                                    break;
                            }
                        }
                if ('${flag}' == 2) {
                    $(".resource_tools").find(".default").show();
                    $("#a1").removeClass("box1").addClass("box2");
                    $("#a2").removeClass("box2").addClass("box1");
                }
                if ('${flag}' ==3) {
                    $(".resource_tools").find(".resource_oper").show();
                    $("#a2").removeClass("box1").addClass("box2");
                    $("#a1").removeClass("box2").addClass("box1");
                }

            });


    function page(page) {
        $a = $(".list-tab a.box2");
        var href = $a.attr("href");
        window.location.href = href + "&page=" + page;
    }



    function addRow() {
        layer.open({
            type: 2,
            title: ['新增资源信息', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            scrollbar: false,
            area: ['800px', '500px'],
            content: '${pageContext.request.contextPath}/admin/tshelves_addView.action',
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
                            layer.alert(data.msg, function (index) {
                                window.location.href = "${pageContext.request.contextPath}/admin/tshelves_listView.action?flag=0";
                                layer.close(index);
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    }
                };
                var cUrl = $("#layui-layer-iframe" + index).contents().find("#cUrl").val();
               	var reg =new RegExp("^((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?$"); 
               	if(reg.test(cUrl)){
               	 	$("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
              		$("#layui-layer-iframe" + index).contents().find("#form").submit();  	
               	}else{
               		alert("url格式错误,请输入http: 或 https:开头");
               	}
            },
            cancel: function (index) {
                layer.close(index);
            }
        });
    }


    <!--修改数据记录-->
    function editRow(sid) {
            layer.open({
                type: 2,
                title: '<strong>资源信息修改</strong>',
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '500px'],
                content: '${pageContext.request.contextPath}/admin/tshelves_editView.action?sid='
                + sid,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    var options = {
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code == 1) {
                                layer.alert(data.msg, function (index) {
                                    window.location.reload();
                                    layer.close(index);
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    };
                    var cUrl = $("#layui-layer-iframe" + index).contents().find("#cUrl").val();
                   	var reg =new RegExp("^((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?$"); 
                   	if(reg.test(cUrl)){
                   	 	$("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                  		$("#layui-layer-iframe" + index).contents().find("#form").submit();  	
                   	}else{
                   		alert("url格式错误,请输入http: 或 https:开头");
                   	}
                },
                cancel: function (index) {
                    layer.close(index);
                }
            });

    }
    function distribute(sid) {
            layer.open({
                type: 2,
                title: '<strong>分配资源</strong>',
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '500px'],
                content: '${pageContext.request.contextPath}/admin/tstrategy_distribute.action?shid='
                + sid,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    var options = {
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code == 1) {
                                layer.alert(data.msg, function (index) {
                                    window.location.reload();
                                    layer.close(index);
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    };
//                     var range = $("#layui-layer-iframe" + index).contents().find("input[name='range']:checked").val();
//                     if(range == 1){
//                     	 var agtCodes = $("#layui-layer-iframe" + index).contents().find("#agtCode").val();
//                     	 if(agtCodes == null){
//                         	 alert("此选择范围下分配时公司必选");
//                         	 return;
//                          }
//                     }else if(range == 2){
//                     	 var communityId = $("#layui-layer-iframe" + index).contents().find("#communityId").val();
//                     	 if(communityId == null){
//                         	 alert("此选择范围下分配时社区必选");
//                         	 return;
//                          }
//                     }
                    $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                    $("#layui-layer-iframe" + index).contents().find("#form").submit();
                },
                cancel: function (index) {
                    layer.close(index);
                }
            });
    }
    function off(sid) {
            layer.open({
                type: 2,
                title: '<strong>下架资源</strong>',
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '500px'],
                content: '${pageContext.request.contextPath}/admin/tstrategy_offView.action?shid='
                + sid,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    var options = {
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code == 1) {
                                layer.alert(data.msg, function (index) {
                                    window.location.reload();
                                    layer.close(index);
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    };
                    $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                    $("#layui-layer-iframe" + index).contents().find("#form").submit();
                },
                cancel: function (index) {
                    layer.close(index);
                }
            });
    }
    function reports(sid) {
            layer.open({
                type: 2,
                title: '<strong>开门惊喜资源报表</strong>',
                shadeClose: true, //点击遮罩关闭层
                area: ['800px', '500px'],
                content: '${pageContext.request.contextPath}/admin/tstrategy_reports.action?shid='
                + sid,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    var options = {
                        success: function (data) {
                            data = JSON.parse(data);
                            if (data.code == 1) {
                                layer.alert(data.msg, function (index) {
                                    window.location.reload();
                                    layer.close(index);
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    };
                    $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                    $("#layui-layer-iframe" + index).contents().find("#form").submit();
                },
                cancel: function (index) {
                    layer.close(index);
                }
            });
    }
</script>
</body>
</html>
